﻿using System;
using Mars.GameCore;

namespace Mars.Network
{
    public static class SerializerHelper
    {
        /// <summary>
        /// 序列化对象
        /// </summary>
        /// <param name="value"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static byte[] Serialize<T>(T value)
        {
#if USE_PROTO_BUF
            return ProtoBufSerializerHelper.Serialize<T>(value);
#else
            return JsonSerializerHelper.Serialize<T>(value);
#endif
        }
        
        /// <summary>
        /// 反序列化数据对象
        /// </summary>
        /// <param name="data">数据</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static object Deserialize(byte[] data, Type type)
        {
#if USE_PROTO_BUF
            return ProtoBufSerializerHelper.Deserialize(data, type);
#else
            return JsonSerializerHelper.Deserialize(data, type);
#endif
        }
    }
}